home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / kaffe-0.2 / lib / native / java.lang / java.lang.Class.c next >
Encoding:
C/C++ Source or Header  |  1996-02-12  |  2.2 KB  |  107 lines

  1. /*
  2.  * java.lang.Class.c
  3.  *
  4.  * Copyright (c) 1996 Systems Architecture Research Centre,
  5.  *           City University, London, UK.
  6.  *
  7.  * See the file "license.terms" for information on usage and redistribution
  8.  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9.  *
  10.  * Written by Tim Wilkinson <tim@sarc.city.ac.uk>, February 1996.
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include <assert.h>
  15. #include <native.h>
  16. #include "../../kaffe/gtypes.h"
  17. #include "../../kaffe/classMethod.h"
  18. #include "defs.h"
  19.  
  20. extern char* addString(char*);
  21. extern object* alloc_object(struct Hjava_lang_Class*);
  22. extern object* alloc_objectarray(int, char*);
  23. extern struct Hjava_lang_Class*    lookupClass(char*);
  24.  
  25. /*
  26.  * Convert string name to class object.
  27.  */
  28. struct Hjava_lang_Class*
  29. java_lang_Class_forName(struct Hjava_lang_String* str)
  30. {
  31.     struct Hjava_lang_Class* c;
  32.     char* s;
  33.     char buf[MAXNAMELEN];
  34.     int i;
  35.  
  36.     /* Get string and convert '.' to '/' */
  37.     javaString2CString(str, buf, sizeof(buf));
  38.     classname2pathname(buf, buf);
  39.  
  40.     c = lookupClass(addString(buf));
  41.     assert(c != 0);
  42.  
  43.     return (c);
  44. }
  45.  
  46. /*
  47.  * Convert class to string name.
  48.  */
  49. struct Hjava_lang_String*
  50. java_lang_Class_getName(struct Hjava_lang_Class* c)
  51. {
  52.     return (makeJavaString(c->name, strlen(c->name)));
  53. }
  54.  
  55. /*
  56.  * Create a new instance of the derived class.
  57.  */
  58. struct Hjava_lang_Object*
  59. java_lang_Class_newInstance(struct Hjava_lang_Class* this)
  60. {
  61.     return (execute_java_constructor(0, 0, this, "()V"));
  62. }
  63.  
  64. /*
  65.  * Return super class.
  66.  */
  67. struct Hjava_lang_Class*
  68. java_lang_Class_getSuperclass(struct Hjava_lang_Class* this)
  69. {
  70.     return (this->superclass);
  71. }
  72.  
  73. HArray* /* [Ljava.lang.Class; */
  74. java_lang_Class_getInterfaces(struct Hjava_lang_Class* this)
  75. {
  76.     object* obj;
  77.     struct Hjava_lang_Class** ifaces;
  78.     int i;
  79.  
  80.     obj = alloc_objectarray(this->interface_len, this->name);
  81.     ifaces = (struct Hjava_lang_Class**)obj->data;
  82.     for (i = 0; i < this->interface_len; i++) {
  83.         ifaces[i] = this->interface[i];
  84.     }
  85.  
  86.     return ((HArray*)obj);
  87. }
  88.  
  89. /*
  90.  * Return the class loader which loaded me.
  91.  * Not currently supported.
  92.  */
  93. struct Hjava_lang_ClassLoader*
  94. java_lang_Class_getClassLoader(struct Hjava_lang_Class* this)
  95. {
  96.     return (0);
  97. }
  98.  
  99. /*
  100.  * Is the class an interface?
  101.  */
  102. long /* bool */
  103. java_lang_Class_isInterface(struct Hjava_lang_Class* this)
  104. {
  105.     return ((this->accflags & ACC_INTERFACE) ? 1 : 0);
  106. }
  107.